#include<reg51.h>
#include<intrins.h>

#define GPIO_DIG   P0	
#define GPIO_PLACE P1	


unsigned char code DIG_CODE[17] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};

unsigned char DisplayData[8]={0};

int time=0,second=0,minute=59,hour=23;

void DigDisplay(); 
void time0_init();



void main(void)
{
	
  time0_init();
	while(1)
	{
		 DisplayData[0]=hour/10;
     DisplayData[1]=hour%10;	 
     DisplayData[2]=16;
     DisplayData[3]=minute/10;
		 DisplayData[4]=minute%10;
     DisplayData[5]=16;
		 DisplayData[6]=second/10;
		 DisplayData[7]=second%10;
		 DigDisplay();
		 
	}				
}


void DigDisplay()
{
	unsigned char i;
	unsigned int j;
  unsigned char temp=0xfe;
	for(i=0; i<8; i++)
	{
		GPIO_DIG = 0x00;
		GPIO_DIG = DIG_CODE[DisplayData[i]];  
		GPIO_PLACE=temp;
		temp = _crol_(temp,1);
    j=50;		
    while(j--);
	}
}


void time0_init()
{
    EA=1;
	  TMOD = 0x10; 
	  TH1 = (65536 - 50000)/256;
	  TL1 = (65536- 50000)%256	;
	  ET1=1;
    TR1=1;    
}
 /*************************************
 [ T1 (1s)] 

*************************************/
void time0(void) interrupt 3      
{
	 
	 TH1 = (65536 - 50000)/256	;
	 TL1 = (65536 - 50000)%256;
	 time++;
   if(time==20)
 	 {   
		 second++;
		 time=0;
	 }
	 
	 if(second==60)
 	 {   
		 minute++;
		 second=0;
	 }
	 
	 if(minute==60)
 	 {   
		 hour++;
		 minute=0;
	 }
	 if(hour==24)
 	 {   
		 hour=0;
	 }
	 
}